﻿using System;
using System.Collections.Generic;
using System.Text;
using AllInOnePluginBL.FileHostingExtractors;
using AllInOnePluginBL.Helpers;
using AllInOnePluginBL.jobs;
using AllInOnePluginBL.SiteInfoScrappers;
using AllInOnePluginBL.SiteScrappers;
using Schedule;

namespace SiteExtractorsConsole
{
    class Program
    {
        //private delegate void dOutput(string p1, DateTime time);
        //private static readonly object monitor = new object();
        //private static readonly ScheduleTimer _Timer = new ScheduleTimer();

        private static int counter = 0;

        static void Main()
        {
            var movieUrl = "http://www.myvod.tv/%D7%94%D7%A0%D7%94%D7%A8-%D7%A2%D7%95%D7%A0%D7%94-1-%D7%A4%D7%A8%D7%A7-1-%D7%AA%D7%A8%D7%92%D7%95%D7%9D-%D7%9E%D7%95%D7%91%D7%A0%D7%94.html";
            var v = new PutLockerExtractor();
            var result = v.ExtractMovieUrl(movieUrl);

            var request = new GenericWebRequest();
            request.RequestCookies = result.Cookies;
            var r = request.GetResponse(result.Link, "http://www.videoweed.es/player/weedplayerv3.swf");


            //var info = TorecNetScraper.GetVideoInformation("The Twilight Saga: Breaking Dawn - Part 1");
            
            //var vidicsScrapper = new VidicsScrapper();
            //vidicsScrapper.Execute(0);


            
            //var contect = Utils.GetPage("http://www.vidics.eu/watch/66457/The-Descendants-2011.html", Encoding.UTF8);
            //v.IsContainVideoLink(contect);



            //var lines = new List<string>
            //                {
            //                    "שלום לכולם האתר ירד לרגל שיפוצים", 
            //                    "-----------------", 
            //                    "עמכם הסליחה"
            //                };

            //var imageCreator = new ImageCreator();
            //var image = imageCreator.CreateImageAndWriteText(lines);
            //image.Save(@"d:\ofer.bmp");
            //var v = new VideozerExtractor();
            //var result = v.ExtractMovieUrl("http://videozer.com/embed/YHZv2V7i");


            //var SartababritParserJob = new SartababritParserJob();
            //SartababritParserJob.Execute(0);))));)

            try
			{
                //MultipleJobTimer();
                //var p = new PluginHandler();
                //p.StartScheduler();

                //var jobsScheduler = new JobsScheduler();
                //jobsScheduler.AddJob("MaintenanceJob", typeof(SitesScrapperJob), DateTime.Now, new TimeSpan(0, 1, 0));
                //jobsScheduler.AddJob("MaintenanceJob", typeof(MaintenanceJob), DateTime.Now, new TimeSpan(0, 0, 10));

                //jobsScheduler.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                //Console.WriteLine("enter q and <enter> to quit.");
                //try { while (String.Compare(Console.ReadLine(), "q", true) != 0); }
                //catch { };
            }
        }

        private static void MultipleJobTimer()
        {
            //var now = DateTime.Now;
            //Delegate d = new dOutput(Output);

            //var item = new SimpleInterval(now, new TimeSpan(0, 0, 10));
            //_Timer.AddJob(item, d, "three");

            //item = new SimpleInterval(now, new TimeSpan(0, 0, 30));
            //_Timer.AddJob(item, d, "two");

            //_Timer.Error += _Timer_Error;
            //_Timer.Start();
        }

        private static void Output(string p1, DateTime time)
        {
            //if (String.Compare(p1, "error", true) == 0)
            //    throw new Exception("error");

            //lock (monitor)
            //{
            //    var actual = DateTime.Now;
            //    Console.WriteLine("{0} - {1} = {2} Msg:{3}", actual, time, (actual - time).TotalMilliseconds, p1);
            //}
        }

        private static void _Timer_Error(object sender, ExceptionEventArgs Args)
        {
            Console.WriteLine(Args.EventTime);
            Console.WriteLine(Args.Error.Message);
            Console.WriteLine(Args.Error.StackTrace);
        }
    }
}
